package com.lakers.notice.springboot.netty.endecode;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.lakers.notice.springboot.netty.SendInfo;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;

import java.util.List;

/**
 * 功能描述: MessageProtocolDecoder
 *
 * @author liqin(zxl)
 * @date 2024/5/3
 */
public class MessageProtocolDecoder extends MessageToMessageDecoder<TextWebSocketFrame> {
    @Override
    protected void decode(ChannelHandlerContext ctx, TextWebSocketFrame textWebSocketFrame, List<Object> out) throws Exception {
        ObjectMapper objectMapper = new ObjectMapper();
        SendInfo sendInfo = objectMapper.readValue(textWebSocketFrame.text(), SendInfo.class);
        out.add(sendInfo);
    }
}
